#!/usr/bin/python3
# coding: utf-8
# file: tarfile_.py
# 2018-06-12
import os, tarfile


def make_tar_gz(source_dir):
	''' 压缩 文件夹 tar'''
	out_file = '{}.tar'.format(source_dir)
	tar = tarfile.open(out_file, 'w:gz')

	for root, dirs, files in os.walk(source_dir):
		# if not dirs: continue
		for file in files:
			if not file.endswith('.py'): continue
			file = os.path.join(root, file)
			print(file)
			tar.add(file)
	tar.close()



if __name__ == '__main__':
	source_dir = "D:\\WorkS\\Test"
	make_tar_gz(source_dir)
